<?php 
ob_start();

session_start();

//checking if the user is logged in if they are then the variables are set and boolean value set to TRUE for $loggedin
if(isset($_SESSION['user_id']))

{
	$name = $_SESSION['f_name'];
	$uid = $_SESSION['user_id'];
	$admin = $_SESSION['level'];
	$loggedin = TRUE;
}
else $loggedin = FALSE;

// session start timer is set for 10minutes of inactivity
$inactive = 600;
//set up of the timer on the session and destroys the session, then diverts the user to the logout.php location
if (isset($_SESSION['timeout'])) {

    // calculate the session's "time to live"
    $sessionTTL = time() - $_SESSION['timeout'];
	
	//if the session has been inactive for longer than SESSSION time then the session is destroyed
    if ($sessionTTL > $inactive) {
        session_destroy();
        $url = BASE_URL . 'logout.php'; // Define the URL.
		 }
}
$_SESSION["timeout"] = time();


//redirects user to not logged in home page 
if(!$loggedin){
				// Redirect the user:
			$url = BASE_URL . 'index1.php'; // Define the URL.
			//ob_end_clean(); // Delete the buffer.
			header("Location:$url");
			exit(); // Quit the script.
}

?> 

  <!DOCTYPE html>
<html>
    <head>
    <!-- Bootstrap -->
    <link href="css/bootstrap.css" rel="stylesheet" media="screen">
    
    
    <!--<link href="css/mystyle.css" rel="stylesheet" type="text/css">-->
	
    <script src="Calendar/codebase/dhtmlxscheduler.js" type="text/javascript" charset="ut-f8"></script>
    <link rel="stylesheet" href="Calendar/codebase/dhtmlxscheduler_glossy.css" type="text/css" charset="utf-8">
			
  </head>
  
  <!-- end of header  -->
  <body>
			<div class="page-header">
				<h1>PTA Helper <small>Take the work out of helping.</small></h1>
			</div>
  <!-- start of fixed nav bar -->
 		<div class="navbar navbar-inverse navbar-fixed-top">
 			<div class="navbar-inner">
				 <div class="container-fluid">
				
                <ul class='nav'>			
					<a class='brand' href='index.php'>Home</a>
								
                                	<li class='divider-vertical'><a href='tasks.php'>Tasks</a></li>
                                       
									   <!-- chks that admin not logged in to display uneditable event list, otherwise editable event list displayed-->
									   <?php
									   if(!"$admin" === '1'){            
                									echo "<li class=\"active\"><a href=\"events.php\">Events</a>
                									</li>";
												}
                                       
										if("$admin" === '1'){
												echo"<li><a href=\"events_edit.php\">Events</a></li>
												<li class='divider-vertical'><a href='users.php'>Manage Users</a></li>
												";
												}											
											
								?>
									<!--<li class='divider-vertical'><a href='reports.php'>Reports</a></li>
                                     <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
                  <ul class="dropdown-menu">
                    <li><a href="#">Action</a></li>
                    <li><a href="#">Another action</a></li>
                    <li><a href="#">Something else here</a></li>
                    <li class="divider"></li>
                    <li class="nav-header">Nav header</li>
                    <li><a href="#">Separated link</a></li>
                    <li><a href="#">One more separated link</a></li>
                  </ul>-->
					</ul>
								
						<p class="navbar-text pull-right">
 						
<?php 
									if($loggedin)//checks if user logged in and produces the top left navigation links.
										{
										echo "<b>Hi $name (user - $uid) &bull;</b> :
										<a href='change_password.php'>Change password</a> |
										<a href='logout.php'>Log out</a>";
										}
								else
										{
									echo 	"<a href='index.php'>Home</a> |
											<a href='account.php'>Account Settings</a> |
											<a href='login.php'>Log in</a>";
										}
//start of page layout
					?>

							</p>
						<div class="nav-collapse collapse">
							
						</div>
    <!---/.nav-collapse -->
       			</div>
  			</div>
    	</div>
    
 <!-- fluid body container -->